package sjtu.ist.warehouse4ws.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import sjtu.ist.warehouse4ws.model.Domainmodel;
import sjtu.ist.warehouse4ws.service.DomainModelService;
import sjtu.ist.warehouse4ws.service.PrivilegeService;

import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowDomainModelListAction extends ActionSupport {
	private DomainModelService domainModelService;
	private PrivilegeService privilegeService;
	private List<Domainmodel> domainModelList = new ArrayList<Domainmodel>();
//	public String execute() {
//		return SUCCESS;
//	}
	
	//获得DomainModel列表
	public String showDomainModelList(){
		List<Domainmodel> templist=domainModelService.getDomainModelList();
		this.domainModelList = new ArrayList<Domainmodel>();
		
		ActionContext actionContext=ActionContext.getContext();
		Map session=actionContext.getSession();		
		int userType=(Integer)(session.get("user_type"));
		String userCompany=session.get("user_company").toString();		
		
		for(Domainmodel d : templist){
			if(privilegeService.checkPrivilege(d.getFileId(),userCompany,userType, "read")){
				domainModelList.add(d);
			}
		}
		return SUCCESS;
	}
	
	@JSON(name = "totalDomainModel")
	public int getTotalDomainModel() {
		return this.domainModelList.size();
	}

	@JSON(name = "DomainModel")
	public List<Domainmodel> getDomainModelList() {
		return this.domainModelList;
	}
	
	// 注入DomainModelService
	public void setDomainModelService(DomainModelService domainModelService) {
		this.domainModelService = domainModelService;
	}
	
	public void setPrivilegeService(PrivilegeService privilegeService) {
		this.privilegeService = privilegeService;
	}
}